﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using XmlSockets.Internal.AbSystem;

namespace LibXmlSocket_UnitTest
{
    class DummyInternalSocket:IInternalSocket
    {
        private List<string> messages = new List<string>();

        private int position = 0;

  


        public void AddReceiveMessage(string value)
        {
            messages.Add(value);

        }

        public void AddReceiveMessages(string[] values)
        {
            string messagebuf = "";
            foreach (var message in values)
            {
                messagebuf += message;
                
            }

            AddReceiveMessage(messagebuf);
        }

        public void AddReceiveMessage(XElement message)
        {
            messages.Add(message.ToString() + "\0");

        }

        public void AddReceiveMessages(XElement[] messages)
        {
            foreach (var message in messages)
            {
                AddReceiveMessage(message);
            }
        }


        public async Task ConnectAsync(string hostName, int port)
        {
            await Task.Run(() => { });
        }

        public async Task<XmlSockets.Internal.IXmlSocketReceiveContent> ReceiveAsync(int size)
        {
            if (position >= messages.Count) AddReceiveMessage("<test p1=\"testvalue\">body</test>\0");
            var message = messages[position];
            position++;
            return await Task<XmlSockets.Internal.IXmlSocketReceiveContent>.Run(() => { return new TestReadContent(message); });
        }

        public async Task SendAsync(XmlSockets.Internal.IXmlSocketSendContent content)
        {
            await Task.Run(() => { });
        }

        public void Dispose()
        {
           
        }

        public IEndPoint LocalEndPoint
        {
            get { throw new NotImplementedException(); }
        }

        public IEndPoint RemorteEndPoint
        {
            get { throw new NotImplementedException(); }
        }
    }
}
